//
//  AdverSelectCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/8/1.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
typealias TipBlock = (_ index:IndexPath)->()
class AdverSelectCell: SelectNameCell {
    var indexPath:IndexPath?
    var tipBlock: TipBlock?
    lazy var textField: NumberTextField = {
        let textField = NumberTextField(changeView: nil, szBounds: CGRect.zero)
        textField.clearButtonMode = UITextFieldViewMode.whileEditing
        return textField
    }()
    
    lazy var tipBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.themeSetImage(ThemeManager.ThemeImageKeys.tradeTip, for: .normal)
        btn.addTarget(self, action: #selector(tip), for: .touchUpInside)
        return btn
    }()
    
    lazy var inforLabel: BaseLabel = {
        let label = BaseLabel(style: .twiceStyle)
        label.font = UIFont.systemFont(ofSize: 15)
        return label
    }()
    
    override func setUpUI() {
        super.setUpUI()
        
        self.nameLabel.font = UIFont.systemFont(ofSize: 12)
        
        self.textField.keyboardType = UIKeyboardType.decimalPad
        self.contentView.addSubview(self.textField)
        self.textField.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(115)
            make.right.equalToSuperview().offset(-90)
            make.top.bottom.equalToSuperview()
        }
       
        self.contentView.addSubview(self.kindLabel)
        self.kindLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-47)
        }
        self.backArrorImage.snp.updateConstraints { (make) in
            make.right.equalToSuperview().offset(-47)
        }
        
        self.contentView.addSubview(self.inforLabel)
        self.inforLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(115)
            make.centerY.equalToSuperview()
        }
        
        self.contentView.addSubview(self.tipBtn)
        
        self.tipBtn.snp.makeConstraints({ (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-5)
            make.width.height.equalTo(30)
        })
        
    }
    func setAdverStyle() {
        self.textField.setValue(UIFont.systemFont(ofSize: 12), forKeyPath: "_placeholderLabel.font")
        self.textField.setPlaceholderColor()
       
    }
    
    func setItem(item:CYAdvertItem)  {
        self.nameLabel.text = item.name
        self.textField.isHidden = !item.isCanWrite
        self.inforLabel.isHidden = item.isCanWrite
        self.backArrorImage.isHidden = item.isCanWrite
        
    }
    
    override func changeColor(isHaveContent: Bool) {
        if isHaveContent {
            self.inforLabel.themeTextColor = ThemeManager.ThemeColorKeys.text1
            self.inforLabel.font = UIFont.systemFont(ofSize: 15)
        }else {
            self.inforLabel.font = UIFont.systemFont(ofSize: 13)
            if ThemeManager.default.currentThemeMode() == .night {
                self.inforLabel.textColor  =  UIColor(hexStr: "#616979")
            }else {
                self.inforLabel.textColor  = UIColor(hexStr: "#b1b2b2")
            }
        }

    }
    
    @objc func tip() {
        if self.tipBlock != nil {
            self.tipBlock!(indexPath!)
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
